using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using Microsoft.ApplicationBlocks.Data;
namespace Customs.Components.SXXK.TOKHAI
{
    public class HangMauDich
    {
        public static DataSet GetHangOfToKhai(string maHaiQuan, string maloaihinh, int sotk, short namdk)
        {
            string connectionString = ConnectionManager.GetConnectionString("SXXK", maHaiQuan);
            string query = "SELECT * from DHANGMDDK where MA_HQ=@MA_HQ and MA_LH=@MA_LH AND NAMDK=@NAMDK AND SOTK=@SOTK";

            SqlParameter[] parameters = new SqlParameter[4];

            parameters[0] = new SqlParameter("@Ma_HQ", SqlDbType.Char);
            parameters[0].Size = 6;
            parameters[0].Direction = ParameterDirection.Input;
            parameters[0].Value = maHaiQuan;

            parameters[1] = new SqlParameter("@MA_LH", SqlDbType.Char);
            parameters[1].Size = 5;
            parameters[1].Direction = ParameterDirection.Input;
            parameters[1].Value = maloaihinh;

            parameters[2] = new SqlParameter("@SOTK", SqlDbType.Int);
            parameters[2].Value = sotk;

            parameters[3] = new SqlParameter("@NAMDK", SqlDbType.SmallInt);
            parameters[3].Value = namdk;

            return SqlHelper.ExecuteDataset(connectionString, CommandType.Text, query, parameters);

        }
        public static DataSet GetDanhSachHang(string maHaiQuan, string maDoanhNghiep,short namdk)
        {
            string connectionString = ConnectionManager.GetConnectionString("SXXK", maHaiQuan);
            string query = "SELECT H.* from DHANGMDDK H inner join DTOKHAIMD T on H.SOTK=T.SOTK and H.MA_LH=T.MA_LH and H.MA_HQ=T.MA_HQ and H.NAMDK=T.NAMDK  where T.MA_HQ=@MA_HQ and T.MA_DV=@MA_DV";
            if (namdk > 0)
                query += " and t.namdk=" + namdk;

            SqlParameter[] parameters = new SqlParameter[2];

            parameters[0] = new SqlParameter("@Ma_HQ", SqlDbType.Char);
            parameters[0].Size = 6;
            parameters[0].Direction = ParameterDirection.Input;
            parameters[0].Value = maHaiQuan;

            parameters[1] = new SqlParameter("@Ma_DV", SqlDbType.VarChar);
            parameters[1].Size = 14;
            parameters[1].Direction = ParameterDirection.Input;
            parameters[1].Value = maDoanhNghiep;

            return SqlHelper.ExecuteDataset(connectionString, CommandType.Text, query, parameters);

        }
    }
}
